var express = require('express');
var router = express.Router();
const applyForService = require("../service/applyForService");

//查询所有
router.get("/", async function (req, res) {
    let { type, value, current, size } = req.query;
    let searchObj = {};//
    if (type) {
        if (type == "number") {
            searchObj[type] = value;
        } else {
            searchObj[type] = { $regex: value };
        }
    }
    let data = await applyForService.find(searchObj, { current: current || 1, size: size || 10 });
    // console.log("dasd", data);
    res.send(data);

})
//根据id删除
router.delete("/:id", async function (req, res) {
    let id = req.params.id;
    // console.log("id", id);
    let data = await applyForService.delete(id)
    res.send(data);
})
// 修改
router.put('/:id', async function (req, res, next) {
    let id = req.params.id
    let data = await applyForService.update(id, req.body);
    res.send(data)
});

//增加
router.post("/", async function (req, res) {
    let data = await applyForService.insert(req.body);
    res.send(data);
})
module.exports = router;